Skip to content

fix(hook): apply http-hook headers and harden hookAdd validation - #281

Merged
LeXwDeX merged 1 commit into
devfrom
fix/http-hook-headers
Aug 15, 2026
Merged

fix(hook): apply http-hook headers and harden hookAdd validation#281
LeXwDeX merged 1 commit into
devfrom
fix/http-hook-headers

Conversation

@LeXwDeX

@LeXwDeX LeXwDeX commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Problem

Review 复盘 hooks/hooksapi 发现(前置 review verdict: BLOCKING):

  • F1 (P1): http 类型 hook 的 headers 字段被 schema 接受但 httpHandler 从未应用——配置 auth headers → 端点 401 → 非 2xx 被转为 exitBlock → PreToolUse 错误拒绝工具调用 / Stop hook 强制最多 5 轮额外模型轮。合法配置产生错误控制流。
  • F2 (concern): hooksapi hookAdd 接受空 command(空 shell 静默 no-op)与非正 timeout(立即 kill)。
  • F7 (note): goal/loop.ts F1 注释与 fix(goal): bound goal-driven turns and map ESC to goal pause #280 落地的 cancel 暂停路径漂移。

Fix

  • hook/settings.ts httpHandler: HttpClientRequest.setHeaders(entry.headers ?? {})(bodyJson 前);非 2xx → exitBlock 与网络错误静默放行语义不变
  • handlers/session.ts hookAdd 逐条校验:command 空/纯空白、timeout ≤ 0 → HttpApiError.BadRequest(与相邻 empty-hooks guard 同形)
  • goal/loop.ts: F1 注释改写为准确描述 cancel 路径同步暂停(pauseForUserCancel, fix(goal): bound goal-driven turns and map ESC to goal pause #280)与 shouldPreempt 作为 DB 失败回退的新分工

Evidence

  • bun typecheck (packages/opencode) 干净
  • 新增 wire 级测试:test/hook/http-handler.test.ts(真实 Bun.serve 断言 authorization/x-hook-test 到达 + 500 exitBlock 路径)
  • 新增 test/server/session-hooks-api.test.ts(真实 HttpApi 面 400/200)
  • 全量 hook 套件 + goal 套件 104 pass / 0 fail
  • httpapi-exercise 场景已按契约门禁补齐(--fail-on-missing

Review 处置说明

DAG 工作流 review 节点曾 REJECT,其两条 FAIL 经核实为误判:pauseForUserCancel 不存在是因为检查基线为 main(#280 尚未合入 main,本 PR 基于 dev);'unrelated changes' 为用户工作区固有文件,本 PR 仅提交 6 个修复相关文件。F1/F2/测试质量三项 review 均 PASS。

- httpHandler now sends entry.headers (auth etc.) with the hook POST; non-2xx and network-error semantics unchanged
- hooksapi hookAdd rejects blank command strings and non-positive timeouts (BadRequest, matching the existing empty-hooks guard)
- refresh the F1 interrupt comment in goal/loop.ts for the cancel-path pause landed with the goal-turn-scope change
- tests: wire-level httpHandler headers test (Bun.serve), hooksapi validation test, httpapi-exercise scenarios
@LeXwDeX
LeXwDeX merged commit 3da7554 into dev Aug 15, 2026
5 checks passed
@LeXwDeX
LeXwDeX deleted the fix/http-hook-headers branch August 15, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant